package com.base.controller;

import com.base.service.DialogBoxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 对话框
 * 
 * @author f
 * 
 */
@Controller
@RequestMapping("/admin")
public class index_DialogBox {

	@Autowired
	private DialogBoxService dialogBoxService; // 对话框信息

	// 对话框首页
	@RequestMapping("/dialogBoxIndex")
	public ModelAndView dialogBoxIndex(HttpServletRequest request) throws Exception {
		String userid = (String) request.getSession().getAttribute("adminUserId"); // 登录的用户ID
		if (userid == null) return new ModelAndView("jsp/loginCheck"); // 未登录
		Map<String, Object> map = new HashMap<>(); // 返回数据对象
		map.put("dialogBox", dialogBoxService.selectByParentId(userid)); // 对话框文字
		return new ModelAndView("jsp/index_DialogBox", map);
	}

	// 跳转添加对话框
	@RequestMapping("/addDialogBox")
	public ModelAndView addMallroll(String userid) throws Exception {
		return new ModelAndView( "jsp/add_DialogBox", "userid", userid);
	}

	// 跳转修改对话框
	@RequestMapping("/updateDialogBox")
	public ModelAndView updateMallroll(String id) throws Exception {
		return new ModelAndView("jsp/update_DialogBox", "dialogBox", dialogBoxService.selectByPrimaryKey(id));
	}
}
